#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3005,mod = 1e9+7,inf = 2e9;
int n,k,dis[N][N],ton[N][N][5],mx[4] = {1,-1,0,0},my[4] = {0,0,1,-1};
vector<pair<int,int>> vec[5];
char ch[N][N];
inline int c(int x,int y)
{
	if(x<0||y<0||x<y) return 0;
	__int128 res = 1;
	for(int i = x;i>x-y;i--) res*=i;
	for(int i = 1;i<=y;i++) res/=i;
	return res%mod;
}
namespace sub{
	map<int,bool> mp;
	void dfs(int x)
	{
		if(x>k)
		{
			int id = 0;
			for(int i = 1;i<=n;i++)
				for(int j = 1;j<=n;j++)
				{
					id*=2;
					if(ch[i][j]=='#') id++;
				}
			mp[id] = 1;
			return;
		}
		for(int i = 1;i<=n;i++)
			for(int j = 1;j<=n;j++)
				if(ch[i][j]=='.')
				{
					bool fl = 0;
					for(int k = 0;k<4;k++)
					{
						int x = i+mx[k],y = j+my[k];
						if(x<1||x>n||y<1||y>n) continue;
						if(ch[x][y]=='#') fl = 1;
					}
					if(fl)
					{
						ch[i][j] = '#';
						dfs(x+1);
						ch[i][j] = '.';
					}
				}
	}
	inline void main()
	{
		dfs(1);
		cout<<mp.size();
	}
}
signed main()
{
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=n;j++)
		{
			cin>>ch[i][j];
			if(ch[i][j]=='#') dis[i][j] = 0;
			else dis[i][j] = inf;
		}
	int T = 4;
	while(T--)
	{
		for(int i = 1;i<=n;i++)
			for(int j = 1;j<=n;j++)
			{
				for(int k = 0;k<4;k++)
				{
					int x = i+mx[k],y = j+my[k];
					if(x<1||x>n||y<1||y>n) continue;
					dis[i][j] = min(dis[i][j],dis[x][y]+1);
				}
			}
	}
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=n;j++)
			if(dis[i][j]<inf) vec[dis[i][j]].push_back({i,j});
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=n;j++)
			for(int k = 0;k<4;k++)
			{
				int x = i+mx[k],y = j+my[k];
				if(x<1||x>n||y<1||y>n) continue;
				if(dis[x][y]<=4) ton[i][j][dis[x][y]]++;
			}
	if(k==1) cout<<vec[1].size();
	else if(k==2)
	{
		int ans = c(vec[1].size(),2);
		for(auto _:vec[2])
		{
			int i = _.first,j = _.second;
			(ans+=ton[i][j][1]);
		}
		cout<<ans;
	}
	else if(k==3)
	{
		int ans = c(vec[1].size(),3);
		for(auto _:vec[2])
		{
			int i = _.first,j = _.second;
			(ans+=c(vec[1].size(),2)-c(vec[1].size()-ton[i][j][1],2)+mod)%=mod;
			(ans+=ton[i][j][1]*(ton[i][j][2]+ton[i][j][3]))%=mod;
		}
		for(auto _:vec[1])
		{
			int i = _.first,j = _.second;
			(ans+=c(ton[i][j][2],2))%=mod;
		}
		cout<<ans;
	}
	else if(n<=5) sub::main();
	else
	{
		cout<<"0";
	}
	return 0;
}

